package com.wan37.logic.shop.service.impl;

import com.wan37.logic.shop.dao.CommodityDao;
import com.wan37.logic.shop.domain.entity.CommodityDO;
import com.wan37.logic.shop.domain.vo.CommodityVO;
import com.wan37.logic.shop.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-08-10 20:45
 **/
@Service("commodityService")
public class CommodityServiceImpl implements CommodityService {
    @Autowired
    private CommodityDao commodityDao;
    @Override
    public List<CommodityVO> findCommodityByShopId(CommodityVO commodityVO) {
        List<CommodityDO> commodityDOList = commodityDao.findCommodityByShopId(commodityVO.getShopId());
        if (commodityDOList == null || commodityDOList.size() == 0){
            return null;
        }
        List<CommodityVO> commodityVOList = new ArrayList<>();
        for (CommodityDO commodityDO : commodityDOList){
            commodityVOList.add(new CommodityVO(commodityDO));
        }
        return commodityVOList;
    }

    @Override
    public CommodityVO findCommodityByShopIdAndCommodityId(CommodityVO commodityVO) {
        List<CommodityDO> commodityDOList = commodityDao.findCommodityByShopIdAndCommodityId(new CommodityDO(commodityVO));
        if (commodityDOList == null || commodityDOList.size() == 0){
            return null;
        }
        return new CommodityVO(commodityDOList.get(0));
    }

    @Override
    public boolean update(CommodityVO commodityVO) {
        return commodityDao.update(new CommodityDO(commodityVO));
    }

    @Override
    public boolean save(CommodityVO commodityVO) {
        return commodityDao.add(new CommodityDO(commodityVO));
    }

    @Override
    public boolean delete(CommodityVO commodityVO) {
        return false;
    }
}
